package com.defect.service.basicsService.basicsServiceImpl;

import com.defect.mapper.ProjectMapper;
import com.defect.po.Project;
import com.defect.service.basicsService.ProjectManagementService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 胡八一
 * @date 2020/07/27 14:31
 */
@Service
public class ProjectManagementServiceImpl implements ProjectManagementService {
    //项目信息的mapper对象
    @Resource
    private ProjectMapper projectMapper;

    /**
     * 分页查询所有项目信息
     * @return 返回所有项目信息对象的PageInfo集合
     */
    @Override
    public PageInfo<Project> queryAllProjectByPage(Project project) {
        System.out.println("当前页:"+project.getPageNum()+"每页显示数量:"+project.getPageSize()+"模糊查询:"+project.getProjectName());
        PageHelper.startPage(project.getPageNum(),project.getPageSize());
        List<Project> all = null;
        if(project.getProjectName() == null || project.getProjectName() == ""){
            all = projectMapper.queryAllProjectByPage();
        }else {
            all = projectMapper.queryAllProjectByPageAndNameOrId(project.getProjectName());
        }
        PageInfo<Project> ProjectPoPageInfo = new PageInfo<>(all);
        return ProjectPoPageInfo;
    }

    /**
     * 新增项目信息
     * @param project
     * @return
     */
    @Override
    public int insertProject(Project project) {
        List<Project> projects = projectMapper.queryAllProjectByPage();
        String pid = Integer.parseInt(projects.get(projects.size()-1).getProjectId())+1+"";
        project.setProjectId(pid);
        //初始为有效
        project.setCreateBy("有效");
        return projectMapper.insertProject(project);
    }

    /**
     * 修改项目信息
     * @param project
     * @return
     */
    @Override
    public int updateProject(Project project) {
        System.out.println("修改成功");
        return projectMapper.updateProject(project);
    }


}
